from machine import Pin, ADC
import time

led_pin = Pin(6, Pin.OUT)
mic_pin = ADC(29)

# 设置阈值，根据实际情况调整
threshold = 0.5

while True:
    # 获取声音模拟值
    mic_value = mic_pin.read_u16() / 65535
    
    # 输出声音模拟值到控制台
    print("Mic analog value: %s" % mic_value)
    
    # 设置LED亮度
    if mic_value >= threshold:
        led_pin.on()
    else:
        led_pin.off()
        
    time.sleep(0.1)